
/**
	树形封装
*/
TreeMenu = function (config, adata) {
	Ext.apply(this, config);
	var loader = new Ext.tree.TreeLoader({dataUrl:"business!queryTree.action", preloadChildren:true, clearOnLoad:true});
	TreeMenu.superclass.constructor.call(this, {collapsible:true, rootVisible:false, lines:true, autoScroll:true, animCollapse:false, animate:false, loader:loader, collapseFirst:true});
	this.on("checkchange", function (node, checked) {
		var treeMenu = this;
		if (node.getDepth() == 1) {
			treeMenu._checkchange(node, checked);
		} else {
			node.expand(false, true, function () {
				treeMenu._checkchange(node, checked);
			});
		}
	});
	this.on("dblclick", function (node, checked) {
		node.getUI().toggleCheck();
	}, this);
};
var root = new Ext.tree.AsyncTreeNode({text:"root", id:"root", draggable:false});

Ext.extend(TreeMenu, Ext.tree.TreePanel, {_checkchange:function (node, checked) {
	node.attributes.checked = checked;
	node.eachChild(function (child) {
		child.ui.toggleCheck(checked);
		child.attributes.checked = checked;
		child.fireEvent("checkchange", child, checked);
	});
	if (node.parentNode.id != "root") {
		var _checked = false;
		var allPNodes = this.getAllParentNodes(node.parentNode);
		for (var i = 0; i < allPNodes.length; i++) {
			var pnode = allPNodes[i];
			pnode.eachChild(function (child) {
				if (child.attributes.checked == true) {
					_checked = true;
					return false;
				}
			});
			if (_checked != pnode.attributes.checked) {
				pnode.ui.toggleCheck(_checked);
				pnode.attributes.checked = _checked;
			}
		}
	}
}, getAllParentNodes:function (node) {
	var parentNodes = [];
	parentNodes.push(node);
	if (node.parentNode) {
		parentNodes = parentNodes.concat(this.getAllParentNodes(node.parentNode));
	}
	return parentNodes;
}});

// 屏蔽树节点双击展开、收拢节点
Ext.override(Ext.tree.TreeNodeUI, {onDblClick:function (e) {
	e.preventDefault();
	if (this.disabled) {
		return;
	}
	if (this.checkbox) {
		this.toggleCheck();
	}
	if (!this.animating && this.node.hasChildNodes()) {
		var isExpand = this.node.ownerTree.doubleClickExpand;
		if (isExpand) {
			this.node.toggle();
		}
	}
	this.fireEvent("dblclick", this.node, e);
}});

